package com.housekeeping.housekeeping.serviceItem.controller;

import com.housekeeping.housekeeping.serviceItem.entity.ServiceItemDetails;
import com.housekeeping.housekeeping.serviceItem.service.ServiceItemService;
import com.housekeeping.housekeeping.serviceItem.service.impl.ServiceItemServiceImpl;
import com.housekeeping.housekeeping.serviceItem.utils.RequestUtils;
import com.housekeeping.housekeeping.serviceItem.utils.ResponseUtils;
import com.housekeeping.housekeeping.serviceItem.utils.StatUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServiceItem/getDetails")
public class ServiceItemDetailsController extends HttpServlet {
    private ServiceItemService service = new ServiceItemServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String aid = RequestUtils.verify(req);
            //非空判断
            if (aid == null) { ResponseUtils.fail(resp, StatUtil.DATA_NULL); }
            else {
                ServiceItemDetails details = service.getItemDetails(aid);
                //获取成功
                if (details != null) {ResponseUtils.success(resp, details,StatUtil.SUCCESS); }
                //获取失败
                else {ResponseUtils.fail(resp, StatUtil.DATA_NULL);}
            }
        } catch (Exception e) {
            e.printStackTrace();
            ResponseUtils.fail(resp, StatUtil.INTERNET_ERR);
        }
    }
}
